
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>

/*
 *@brief:两个队列;
 *
 */
ngx_queue_t  ngx_posted_accept_events;   //缓存接收网络连接的队列;
ngx_queue_t  ngx_posted_events;  //缓存接收网络读写事件的队列;


/*@brief:
 *@para:ngx_cycle_t  *cycle:  nginx 服务的上下文;
 *		ngx_queue_t  *posted: 要检查的队列；
 *
 */
void ngx_event_process_posted(ngx_cycle_t *cycle, ngx_queue_t *posted)
{
	ngx_log_error(NGX_LOG_DEBUG, cycle->log, 0, "enter [function]{%s} to process posted event......!",__func__);
    ngx_queue_t  *q;
    ngx_event_t  *ev;
   
	while (!ngx_queue_empty(posted)) { //判断队列是否为空?

        q = ngx_queue_head(posted); //不为空的情形下去 取出一个节点出来, 
        ev = ngx_queue_data(q, ngx_event_t, queue);

        ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "posted event %p", ev);

        ngx_delete_posted_event(ev);  //从队列中删除该节点;

        ev->handler(ev); //执行对应的回调函数
    }
}
